#!/bin/sh

# get linux kernel is 32 or 64bit system
KERNEL=$(uname -m)

# get Ubuntu version
VERSION=$(lsb_release -r)

echo $KERNEL $VERSION

# check if dcom3g was installed then remove it
DCOM3G=$(ls /usr/sbin/ |grep dcom3g)
case "$DCOM3G" in
*dcom3g*)
	echo "D-Com 3G was installed, it is removed now!"
	case "$KERNEL" in
	*x86_64*)
		apt-get remove vt1000-amd64
		;;
	*)
		apt-get remove vt1000-i386
		;;
	esac
	;;
*)
	;;
esac

# install dependence and vt1000 packages with each version Ubuntu
# we only install libjpeg62 for Ubuntu from 12.04 to greater
case "$KERNEL" in
*x86_64*)
	echo "===========Build for Ubuntu 64bit============"
	case "$VERSION" in
	*10.04*)
		echo "Ubuntu 10.04"
		dpkg -i 64bits/libsdl_amd64/libsdl1.2_amd64_10.04.deb
		;;
	*10.10*)
		echo "Ubuntu 10.10"
		;;
	*11.04*)
		echo "Ubuntu 11.04"
		dpkg -i 64bits/libsdl_amd64/libsdl1.2_amd64_11.04.deb
		;;
	*11.10*)
		echo "Ubuntu 11.10"
		dpkg -i 64bits/libsdl_amd64/libsdl1.2_amd64_11.10.deb
		;;
	*)
		echo "Ubuntu from 12.04"
		dpkg -i 64bits/libjpeg62_amd64.deb
		dpkg -i 64bits/libsdl_amd64/libsdl1.2_amd64_12.04.deb
		;;
	esac
	dpkg -i 64bits/vt1000-amd64.deb
	;;
*)
	echo "===========Build for Ubuntu $VERSION 32bit============"
	case "$VERSION" in
	*10.04*)
		echo "Ubuntu 10.04"
		dpkg -i 32bits/libsdl_i386/libsdl1.2_i386_10.04.deb
		;;
	*10.10*)
		echo "Ubuntu 10.10"
		;;
	*11.04*)
		echo "Ubuntu 11.04"
		dpkg -i 32bits/libsdl_i386/libsdl1.2_i386_11.04.deb
		;;
	*11.10*)
		echo "Ubuntu 11.10"
		dpkg -i 32bits/libsdl_i386/libsdl1.2_i386_11.10.deb
		;;
	*)
		echo "Ubuntu from 12.04"
		dpkg -i 32bits/libjpeg62_i386.deb
		dpkg -i 32bits/libsdl_i386/libsdl1.2_i386_12.04.deb
		;;
	esac
	dpkg -i 32bits/vt1000-i386.deb
	;;
esac

# copy help folder to install folder (usr/share/dcom)
cp -r ../manual /usr/share/dcom3g/
chmod 777 -R /usr/share/dcom3g/manual/
